﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Program
    {


        private SerialPort _serialPort;


        static void Main(string[] args)
        {
            string b = "b";
            Task.Run(() => { Thread.Sleep(1000); Console.WriteLine(b); });
            Console.WriteLine("a");
            /*
            var _serialPort = new SerialPort("com12", 9600, Parity.None, 8, StopBits.One);
            _serialPort.Open();
            var hexString = "49310001090004C74493";
            var b = HexStringToByteArray(hexString);
            _serialPort.Write(b,0,b.Length);
            Thread.Sleep(200);
            var blen = _serialPort.BytesToRead;
            byte[] buffer = new byte[blen];
            _serialPort.Read(buffer, 0, blen);
            StringBuilder sb = new StringBuilder();
            foreach (var v in buffer)
            {
                sb.Append(((int)v).ToString("X2"));
            }
            Console.WriteLine(sb.ToString());
            */
            Console.ReadLine();
        }
        public static string HexToAscii(string hexString)
        {
            // 移除所有空格和连字符
            hexString = hexString.Replace(" ", "").Replace("-", "");

            if (hexString.Length % 2 != 0)
                throw new ArgumentException("HEX字符串长度必须是偶数");

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hexString.Length; i += 2)
            {
                string hexByte = hexString.Substring(i, 2);
                byte byteValue = Convert.ToByte(hexByte, 16);
                sb.Append((char)byteValue);
            }
            return sb.ToString();
        }
        private static byte[] HexStringToByteArray(string hex)
        {
            if (hex.Length % 2 != 0)
            {
                throw new ArgumentException("HEX字符串长度必须是偶数");
            }

            byte[] bytes = new byte[hex.Length / 2];
            for (int i = 0; i < bytes.Length; i++)
            {
                string hexByte = hex.Substring(i * 2, 2);
                bytes[i] = Convert.ToByte(hexByte, 16);
            }
            return bytes;
        }
    }
}
